package com.maiji.cloud.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.maiji.cloud.entities.shopingmall.GoodsCommentThumbsUp;
import com.maiji.cloud.mapper.GoodsCommentThumbsUpMapper;
import com.maiji.cloud.service.GoodsCommentThumbsUpService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.maiji.cloud.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class GoodsCommentThumbsUpServiceImpl extends ServiceImpl<GoodsCommentThumbsUpMapper, GoodsCommentThumbsUp> implements GoodsCommentThumbsUpService {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    public GoodsCommentThumbsUp selectOneByRedis(String goods_comment_id, String user_id) {
        String redisKey = RedisUtil.getRedisKey(REDISNAMESPACE, goods_comment_id, user_id);
        GoodsCommentThumbsUp goodsCommentThumbsUp = (GoodsCommentThumbsUp) redisTemplate.opsForValue().get(redisKey);
        if (goodsCommentThumbsUp == null) {
            EntityWrapper<GoodsCommentThumbsUp> entityWrapper = new EntityWrapper<>();
            entityWrapper.eq("goods_comment_id", goods_comment_id);
            entityWrapper.eq("user_id", user_id);
            entityWrapper.eq("is_cancel", 0);
            goodsCommentThumbsUp = selectOne(entityWrapper);
            if (goodsCommentThumbsUp != null) RedisUtil.setObject(redisTemplate, redisKey, goodsCommentThumbsUp);
        }
        return goodsCommentThumbsUp;
    }
}
